﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：张雄
    //
    // 文件名：CancelOrderSecondLeavel.cs
    // 文件功能描述：采购单次数
    // 创建标识：张雄 2011-8-10
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase
{
    public partial class SortSourceRateCount : BasePage
    {
        string HospitalID = "";

        //public SortSourceRateCount() 
        //{
        //    this.ModuleNo = Module.趋势走向.ToString();
        //    this.PageOperateType = OperateType.采购单次数.ToString();
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Function.SetDatetime(this.txtTimeFrom, this.txtTimeTo);

                areaID.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;

                DataBind();
            }
        }

        #region 数据绑定

        /// <summary>
        /// 绑定数据 by：张雄
        /// </summary>
        private void DataBind()
        {
            try
            {

                #region 时间条件

                string timeFrom = string.Intern(this.txtTimeFrom.Text);

                string timeTo = string.Intern(this.txtTimeTo.Text);

                #endregion

                string hosName = this.txtHospitalname.Text;

                string areaid = this.areaID.SelectedAreaID;

                string whereAreaId = "";

                whereAreaId = Function.GetConditionOfAreaId(whereAreaId, areaid) as string;

                int t = 0;

                //按照不同的统计方式显示不的列，默认为医院统计
                string flag = "0";  //0：代表“医院统计” 1：代表“县区统计”

                if (ddlFenType.SelectedValue == "按医院统计")
                {
                    gvwProcureCatalog.Columns[1].Visible = false;
                    gvwProcureCatalog.Columns[2].Visible = true;
                    flag = "0";
                }
                else if (ddlFenType.SelectedValue == "按县区统计")
                {
                    gvwProcureCatalog.Columns[2].Visible = false;
                    gvwProcureCatalog.Columns[1].Visible = true;
                    flag = "1";
                }
                else
                {
                    gvwProcureCatalog.Columns[2].Visible = false;
                    gvwProcureCatalog.Columns[1].Visible = true;
                    flag = "2";
                }

                DataTable dt = HZ.Supervise.BLLFactory.ExecuteContext().ExecuteRateOfHosSourceCount(timeFrom, timeTo, hosName, whereAreaId, flag, this.AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out t);

                AspNetPager1.RecordCount = t;

                this.gvwProcureCatalog.DataSource = dt;

                this.gvwProcureCatalog.DataBind();

            }
            catch (Exception e)
            {
                e.ToString();

                HZ.Web.WebUtil.Alert("请输入正确的格式！");
            }
        }

        #endregion

        /// <summary>
        /// 条件查询
        /// by：张雄
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            #region 时间条件

            string timeFrom = string.Intern(this.txtTimeFrom.Text);

            string timeTo = string.Intern(this.txtTimeTo.Text);

            #endregion

            string hosName = this.txtHospitalname.Text;

            string areaid = this.areaID.SelectedAreaID;

            string whereAreaId = "";

            whereAreaId = Function.GetConditionOfAreaId(whereAreaId, areaid) as string;

            //按照不同的统计方式显示不的列，默认为医院统计
            string flag = "0";  //0：代表“医院统计” 1：代表“县区统计”

            if (ddlFenType.SelectedValue == "按医院统计")
            {
                gvwProcureCatalog.Columns[1].Visible = false;
                gvwProcureCatalog.Columns[2].Visible = true;
                flag = "0";
            }
            else if (ddlFenType.SelectedValue == "按县区统计")
            {
                gvwProcureCatalog.Columns[2].Visible = false;
                gvwProcureCatalog.Columns[1].Visible = true;
                flag = "1";
            }
            else
            {
                gvwProcureCatalog.Columns[2].Visible = false;
                gvwProcureCatalog.Columns[1].Visible = true;
                flag = "2";
            }

            int t = 0;

            DataTable dt = HZ.Supervise.BLLFactory.ExecuteContext().ExecuteRateOfHosSourceCount(timeFrom, timeTo, hosName, whereAreaId, flag, 0, 1, out t);

            AspNetPager1.RecordCount = t;

            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, this.gvwProcureCatalog);
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            DataBind();
        }

    }
}
